package cn.xjt.config;

import org.aopalliance.intercept.Interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 内容：
 *
 * @author
 * @date 2020/9/26-16:48
 */
public class Logininterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		HttpSession session = request.getSession();
		//如果请求路径包含login，则放行
		if(request.getRequestURI().contains("gologin"))
		{
			return true;
		}
		if(request.getRequestURI().contains("l"))
		{
			return true;
		}
		//放心：判断什么情况下登录
		if(session.getAttribute("userLoginInfo")!=null)
		{
			//如果得到得session不为空，放行
			return true;
		}

		request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
		return false;
	}
}
